package com.wst.system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wst.system.security.entity.dto.SysMenuEntityListDto;
import com.wst.system.server.entity.dto.SysFileGroupListDto;
import com.wst.system.server.entity.dto.SysFileGroupTreeDto;
import com.wst.system.util.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wst.system.config.exception.GlobalExcetion;
import java.io.Serializable;

import com.wst.system.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.wst.system.server.service.SysFileGroupService;
import com.wst.system.server.entity.SysFileGroup;
import com.wst.system.server.entity.vo.SysFileGroupVo;
import com.wst.system.server.entity.vo.PageSearchVo;
import org.springframework.validation.annotation.Validated;
import java.util.List;

import com.wst.system.server.entity.vo.DelManyDataVo;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author X.I.O
 * @since 2025-03-03
 */

@RestController
@Api(tags = {"的服务类"})
@RequestMapping("/sys-file-group")
public class SysFileGroupController  {

        @Autowired
        private SysFileGroupService sysFileGroupService;


        @PostMapping("/saveorupdate")
        @ApiOperation(value = "的新增/更新接口",notes = "的新增接口")
        public JSONObject save(@RequestBody @Validated SysFileGroupVo sysFileGroupVo) throws GlobalExcetion{
                sysFileGroupService.saveOrUpdateSysFileGroup(sysFileGroupVo);
            return ResultUtil.successInfo("操作成功");
        }


        @PostMapping("/save")
        @ApiOperation(value = "的新增接口",notes = "的新增接口")
        public JSONObject save(@RequestBody SysFileGroup sysFileGroup) throws GlobalExcetion{
                sysFileGroupService.saveSysFileGroup(sysFileGroup);
            return ResultUtil.successInfo("保存成功");
        }


        @PostMapping("/update")
        @ApiOperation(value = "的更新接口",notes = "的更新接口")
        public JSONObject update(@RequestBody SysFileGroup sysFileGroup) throws GlobalExcetion{
                sysFileGroupService.updateSysFileGroupById(sysFileGroup);
            return ResultUtil.successInfo("更新成功");
        }

        @GetMapping("/gettreelist")
        public JSONObject getTreeList() throws GlobalExcetion {
            Integer userId=SecurityUtil.getUserId();
            List<SysFileGroupTreeDto> treeDtos=sysFileGroupService.childListByUid(userId);
            return ResultUtil.successInfo(treeDtos);
        }

        @DeleteMapping("/delbyid")
        @ApiOperation(value = "的删除接口",notes = "的删除接口")
        public JSONObject delete(@RequestParam("id") Serializable id) throws GlobalExcetion{
            boolean flag = sysFileGroupService.removeById(id);
            if(flag){
                return ResultUtil.successInfo("删除成功");
            }else {
                return ResultUtil.errorInfo("删除失败");
            }
        }

        @PostMapping("/del/batch")
        @ApiOperation(value = "的批量删除接口",notes = "的批量删除接口")
        public JSONObject deleteBatch(@RequestBody DelManyDataVo vo) throws GlobalExcetion {
            boolean flag =  sysFileGroupService.removeByIds(vo.getIds());
            if(flag){
                return ResultUtil.successInfo("删除成功");
            }else {
                return ResultUtil.errorInfo("删除失败");
            }
        }

        @GetMapping("/getall")
        @ApiOperation(value = "的获取全部接口",notes = "的获取全部接口")
        public JSONObject findAll() throws GlobalExcetion {
            List<SysFileGroupListDto> list=sysFileGroupService.listAll();
            Integer count=list==null?0:list.size();
            return ResultUtil.successInfoTable(count,list);
        }

        @GetMapping("/getbyid")
        @ApiOperation(value = "的获取一个接口",notes = "的获取一个接口")
        public JSONObject findOne(@RequestParam("id") Serializable id) throws GlobalExcetion {
            SysFileGroup data= sysFileGroupService.getById(id);
            return ResultUtil.successInfo(data);
        }

        @PostMapping("/page")
        @ApiOperation(value = "的分页接口",notes = "的分页接口")
        public JSONObject findPage(@RequestBody @Validated PageSearchVo pageSearchVo) throws GlobalExcetion {
            IPage<SysFileGroup> data=sysFileGroupService.page(pageSearchVo);
            return ResultUtil.successInfoTable(data.getTotal(),data.getRecords());
        }
}

